# -*- coding: utf-8 -*-
# @Author: long
# @Date:   2018-06-03 11:53:34
# @Last Modified by:   long
# @Last Modified time: 2018-06-03 11:58:45


import sqlite3

from filelist import PathList
from linuxfsconnect import LinuxFSPathConnect
import re

class PathFileIndex(object):
	"""docstring for PathFileIndex"""
	def __init__(self):
		super(PathFileIndex, self).__init__()

	def handle_path_list(self, cur_dir, file_name, isdir=False, join_path=None):
		if isdir:
			print "d-",
		else:
			print "--",
		uri = join_path(cur_dir, file_name)
		link = join_path(self.link_prefix, uri)
		print uri, link


	def gen_index(self, root_uri, link_prefix):
		max_depth = 1
		self.link_prefix = link_prefix
		# now only local filesystem scan
		path_conn = LinuxFSPathConnect(root_uri)
		PathList().list_files(path_conn, self.handle_path_list, path_conn.get_root_uri(), max_depth)



def main():
	pfi = PathFileIndex()
	pfi.gen_index(".", "http://localhost")



if __name__ == '__main__':
	main()
